<template>
	<div class="login-wrap">
		<el-form class="login-container">
			<h1 class="title">用户登录</h1>
			<el-form-item>
				<el-input type="text" v-model="username" placeholder="用户账号" autocomplete="off"></el-input>
			</el-form-item>
			<el-form-item>
				<el-input type="password" v-model="password" placeholder="用户密码" autocomplete="off"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="doLogin" style="width: 100%;">登录</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>
<script>
	import { getLocalStorage, setLocalStorage } from '@/utils';
    import axios from 'axios';
	export default {
		name: 'Login',
		data() {
			return {
				username: '',
				password: ''
			}
		},
		beforeDestroy() {
			this.resetData();
		},
		mounted() {
			this.resetData();
		},
		methods: {
			resetData(){
				setLocalStorage('shopName',0);
				setLocalStorage('shopId',0);
			},
			doLogin() {
				let username = this.username;
				let password = this.password;
				let url = "http://wx.zsltwl.cn/Wxsite/Agents/api";
				let params = {
					username: username,
					password: password,
					api_name: 'shopLogin'
				}
				//发起ajax请求-GET(注意参数必须保存到params属性中)
				axios.get(url, {
					params: params
				}).then(resp => {
					console.log(resp)
					if (resp.data.code == 1) {
						// this.$message({
						// 	type: 'success',
						// 	message: '登录成功'
						// });
						window["$message"]({
						  message: '登录成功',
						  type: "warning",
						});
						console.log('123123',resp)
						setLocalStorage('shopName',resp.data.data.info.name);
						setLocalStorage('shopId',resp.data.data.info.shop_id);
						var sid = getLocalStorage('shopId');
						console.log('打印ID',sid);
						
						this.$router.push({
							path: '/indexc',
							name: 'indexc',
							params: {
								mobile: 999
							}
						})
					}else if (resp.data.code == 2) {
						if(resp.data.data.aid ==1){
							// this.$message({
							// 	type: 'success',
							// 	message: '登录成功'
							// });
							window["$message"]({
							  message: '登录成功',
							  type: "warning",
							});
							console.log('123123',resp)
							setLocalStorage('shopId','999sa');
							var sid = getLocalStorage('shopId');
							console.log('打印ID',sid);
							
							this.$router.push({
								path: '/index',
								name: 'index',
								params: {
									mobile: 999
								}
							})
						}else{
							window["$message"]({
							  message: '登录成功',
							  type: "warning",
							});
							console.log('123123',resp)
							setLocalStorage('shopName',resp.data.data.name);
							setLocalStorage('shopId',resp.data.data.shop_id);
							var sid = getLocalStorage('shopId');
							console.log('打印ID',sid);
							
							this.$router.push({
								path: '/indexc',
								name: 'indexc',
								params: {
									mobile: 999
								}
							})
						}
					} else {
						setLocalStorage('shopId',0);
						console.log(resp.data)
						// this.$message({
						// 	type: 'error',
						// 	message: resp.data.message
						// });
						window["$message"]({
						  message: '登录失败',
						  type: "warning",
						});
						return;
					}
				}).catch(err => {
					console.log(err);
				})
			}
		}
	}
</script>
<style>
	.login-wrap {
		box-sizing: border-box;
		width: 100%;
		height: 100%;
		padding-top: 10%;
		background-image: url();
		/* background-color: #112346; */
		background-repeat: no-repeat;
		background-position: center right;
		background-size: 100%;
	}

	.login-container {
		border-radius: 10px;
		margin: 0px auto;
		width: 350px;
		padding: 30px 35px 15px 35px;
		background: #fff;
		border: 1px solid #eaeaea;
		text-align: left;
		box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
	}

	.title {
		margin: 0px auto 40px auto;
		text-align: center;
		color: #505458;
	}
</style>